package cn.javass.chapter6.web.controller;


import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

//@RequestMapping
@Controller
public class HelloWorldController {

    @RequestMapping(value = "/hello")
    public ModelAndView helloWorld() {
		//1、收集参数
		//2、绑定参数到命令对象
		//3、调用业务对象
		//4、选择下一个页面
		ModelAndView mv = new ModelAndView();
		
		List<String> list=new ArrayList<String>();
		for(int i=0;i<10;i++){
			String temp=i+"c";
			list.add(temp);
		}
		
		mv.addObject("list", list);
		//添加模型数据 可以是任意的POJO对象
		mv.addObject("message", "Hello World!");
		
		mv.addObject("user", "this user");
		//设置逻辑视图名，视图解析器会根据该名字解析到具体的视图页面
		mv.setViewName("hello");
		return mv;
	}
    
    @RequestMapping(value="first")
    public ModelAndView first(){
    	List li=new ArrayList<Integer>();
    	for(int i=0;i<20;i++){
    		li.add(i);
    	}
    	ModelAndView mv=new ModelAndView();
    	mv.addObject("list", li);
    	mv.addObject("user", "字符串操作");
    	mv.addObject("test", "Tom & Jerry");
    	mv.setViewName("first");
    	return mv;
    }
    
    @RequestMapping(value="forth")
    public ModelAndView forth(){
    	
    	ModelAndView mv=new ModelAndView();
    	mv.setViewName("forth");
    	return mv;
    }
}
